package com.seraph.zys.web.pccexport;

import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.seraph.bi.suite.support.web.base.BaseResponse;
import com.seraph.bi.suite.support.web.json.JsonProviderController;
import com.seraph.zys.dao.ScOrgDAO;

@Controller
@RequestMapping("/repUnLockOrLock.do")
public class RepUnLockOrLockController extends JsonProviderController {

	@Autowired
	private ScOrgDAO scOrgDAO;

	public void setScOrgDAO(ScOrgDAO scOrgDAO) {
		this.scOrgDAO = scOrgDAO;
	}

	@Override
	protected Object handleJsonRequest(HttpServletRequest request,
			HttpServletResponse response) {
		String fiscalYear = getFiscalYear();
		String orgCode = request.getParameter("orgCode");
		String lockFlag= request.getParameter("lockFlag");
		if(lockFlag!=null){
			if("1".equals(lockFlag.trim())){
				scOrgDAO.lockReport(fiscalYear, orgCode);
				return new BaseResponse(BaseResponse.TRUE, "锁定成功！");
			}else if("0".equals(lockFlag.trim())){
				scOrgDAO.unLockReport(fiscalYear, orgCode);
				return new BaseResponse(BaseResponse.TRUE, "解锁成功！");
			}
		}
		
		return new BaseResponse(BaseResponse.FALSE, "操作失败！");
	}
	private String getFiscalYear() {
		return String
		.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 1);
	}

}
